<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="中文名称" prop="chineseName">
        <el-input
          v-model="queryParams.chineseName"
          placeholder="请输入中文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中文名称-图谱" prop="chineseNameKg">
        <el-input
          v-model="queryParams.chineseNameKg"
          placeholder="请输入中文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称-图谱" prop="englishNameKg">
        <el-input
          v-model="queryParams.englishNameKg"
          placeholder="请输入英文名称-图谱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="英文名称" prop="englishName">
        <el-input
          v-model="queryParams.englishName"
          placeholder="请输入英文名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:activedata:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:activedata:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:activedata:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="activedataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="中文名称" show-overflow-tooltip    align="center" prop="chineseName" />
      <el-table-column label="中文名称-图谱"  show-overflow-tooltip   align="center" prop="chineseNameKg" />
      <el-table-column label="英文名称-图谱" show-overflow-tooltip    align="center" prop="englishNameKg" />
      <el-table-column label="英文名称"  show-overflow-tooltip   align="center" prop="englishName" />
      <el-table-column label="主办方-图谱"  show-overflow-tooltip   align="center" prop="organizerKg" />
      <el-table-column label="主办方" show-overflow-tooltip    align="center" prop="organizer" />
      <el-table-column label="参演国家/机构"  show-overflow-tooltip   align="center" prop="participatingCountriesInstitutions" />
      <el-table-column label="起始时间-图谱" show-overflow-tooltip    align="center" prop="startTimeKg" />
      <el-table-column label="起始时间"  show-overflow-tooltip   align="center" prop="startTime" />
      <el-table-column label="结束时间-图谱"  show-overflow-tooltip    align="center" prop="endTimeKg" />
      <el-table-column label="结束时间" show-overflow-tooltip    align="center" prop="endTime" />
      <el-table-column label="举办形式-图谱"  show-overflow-tooltip   align="center" prop="formOfEventKg" />
      <el-table-column label="举办形式" show-overflow-tooltip    align="center" prop="formOfEvent" />
      <el-table-column label="是否系列演习" show-overflow-tooltip    align="center" prop="isSeries" />
      <el-table-column label="举行周期" show-overflow-tooltip    align="center" prop="exercisePeriodicity" />
      <el-table-column label="演习目的" show-overflow-tooltip    align="center" prop="purposeOfExercise" />
      <el-table-column label="演习规模"  show-overflow-tooltip   align="center" prop="scaleOfExercise" />
      <el-table-column label="演习地点-图谱" show-overflow-tooltip    align="center" prop="locationOfExerciseKg" />
      <el-table-column label="演习地点"  show-overflow-tooltip   align="center" prop="locationOfExercise" />
      <el-table-column label="演习场景设置"  show-overflow-tooltip   align="center" prop="scenarioSetup" />
      <el-table-column label="使用平台-图谱" show-overflow-tooltip    align="center" prop="platformUsedKg" />
      <el-table-column label="使用平台"  show-overflow-tooltip   align="center" prop="platformUsed" />
      <el-table-column label="其他信息" show-overflow-tooltip    align="center" prop="otherInformation" />
      <el-table-column label="操作"  fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:activedata:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:activedata:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改演习数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="中文名称" prop="chineseName">
          <el-input v-model="form.chineseName" placeholder="请输入中文名称" />
        </el-form-item>
        <el-form-item label="中文名称-图谱" prop="chineseNameKg">
          <el-input v-model="form.chineseNameKg" placeholder="请输入中文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称-图谱" prop="englishNameKg">
          <el-input v-model="form.englishNameKg" placeholder="请输入英文名称-图谱" />
        </el-form-item>
        <el-form-item label="英文名称" prop="englishName">
          <el-input v-model="form.englishName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="主办方-图谱" prop="organizerKg">
          <el-input v-model="form.organizerKg" placeholder="请输入主办方-图谱" />
        </el-form-item>
        <el-form-item label="主办方" prop="organizer">
          <el-input v-model="form.organizer" placeholder="请输入主办方" />
        </el-form-item>
        <el-form-item label="参演国家/机构" prop="participatingCountriesInstitutions">
          <el-input v-model="form.participatingCountriesInstitutions" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="起始时间-图谱" prop="startTimeKg">
          <el-input v-model="form.startTimeKg" placeholder="请输入起始时间-图谱" />
        </el-form-item>
        <el-form-item label="起始时间" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入起始时间" />
        </el-form-item>
        <el-form-item label="结束时间-图谱" prop="endTimeKg">
          <el-input v-model="form.endTimeKg" placeholder="请输入结束时间-图谱" />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="举办形式-图谱" prop="formOfEventKg">
          <el-input v-model="form.formOfEventKg" placeholder="请输入举办形式-图谱" />
        </el-form-item>
        <el-form-item label="举办形式" prop="formOfEvent">
          <el-input v-model="form.formOfEvent" placeholder="请输入举办形式" />
        </el-form-item>
        <el-form-item label="是否系列演习" prop="isSeries">
          <el-input v-model="form.isSeries" placeholder="请输入是否系列演习" />
        </el-form-item>
        <el-form-item label="举行周期" prop="exercisePeriodicity">
          <el-input v-model="form.exercisePeriodicity" placeholder="请输入举行周期" />
        </el-form-item>
        <el-form-item label="演习目的" prop="purposeOfExercise">
          <el-input v-model="form.purposeOfExercise" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="演习规模" prop="scaleOfExercise">
          <el-input v-model="form.scaleOfExercise" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="演习地点-图谱" prop="locationOfExerciseKg">
          <el-input v-model="form.locationOfExerciseKg" placeholder="请输入演习地点-图谱" />
        </el-form-item>
        <el-form-item label="演习地点" prop="locationOfExercise">
          <el-input v-model="form.locationOfExercise" placeholder="请输入演习地点" />
        </el-form-item>
        <el-form-item label="演习场景设置" prop="scenarioSetup">
          <el-input v-model="form.scenarioSetup" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="使用平台-图谱" prop="platformUsedKg">
          <el-input v-model="form.platformUsedKg" placeholder="请输入使用平台-图谱" />
        </el-form-item>
        <el-form-item label="使用平台" prop="platformUsed">
          <el-input v-model="form.platformUsed" placeholder="请输入使用平台" />
        </el-form-item>
        <el-form-item label="其他信息" prop="otherInformation">
          <el-input v-model="form.otherInformation" type="textarea" placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="${comment}" prop="allInfo">-->
<!--          <el-input v-model="form.allInfo" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="图片" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'image'"
              :biz-type="'download'"
              :limit="1"
              style="margin-left: 20px"
              table-type="4"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="原文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz001'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="4"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>

      <el-form ref="formfj" label-width="120px">
        <el-form-item label="译文文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz002'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="4"
            ></FileUpload>
          </div>
        </el-form-item>

      </el-form>
      <el-form ref="formfj" label-width="120px">
        <el-form-item label="精翻文件" prop="ysSm">
          <div>
            <FileUpload
              v-if="open"
              ref="expertRef"
              :disabled="true"
              :businessId="form.id"
              :business-type="'bz003'"
              :biz-type="'download'"
              :limit="1"
              :file-size="200"
              :file-type="['pdf']"
              style="margin-left: 20px"
              table-type="4"
            ></FileUpload>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listActivedata, getActivedata, delActivedata, addActivedata, updateActivedata } from "@/api/business/activedata";
import { guid } from '@/utils/utils'

import FileUpload from '@/components/fileUpload_neww.vue'
import Pictures from '@/components/Pictures'
export default {
  name: "Activedata",
  components: { Pictures,FileUpload },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 演习数据表格数据
      activedataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        chineseName: null,
        chineseNameKg: null,
        englishNameKg: null,
        englishName: null,
        organizerKg: null,
        organizer: null,
        participatingCountriesInstitutions: null,
        startTimeKg: null,
        startTime: null,
        endTimeKg: null,
        endTime: null,
        formOfEventKg: null,
        formOfEvent: null,
        isSeries: null,
        exercisePeriodicity: null,
        purposeOfExercise: null,
        scaleOfExercise: null,
        locationOfExerciseKg: null,
        locationOfExercise: null,
        scenarioSetup: null,
        platformUsedKg: null,
        platformUsed: null,
        otherInformation: null,
        allInfo: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询演习数据列表 */
    getList() {
      this.loading = true;
      listActivedata(this.queryParams).then(response => {
        this.activedataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        chineseName: null,
        chineseNameKg: null,
        englishNameKg: null,
        englishName: null,
        organizerKg: null,
        organizer: null,
        participatingCountriesInstitutions: null,
        startTimeKg: null,
        startTime: null,
        endTimeKg: null,
        endTime: null,
        formOfEventKg: null,
        formOfEvent: null,
        isSeries: null,
        exercisePeriodicity: null,
        purposeOfExercise: null,
        scaleOfExercise: null,
        locationOfExerciseKg: null,
        locationOfExercise: null,
        scenarioSetup: null,
        platformUsedKg: null,
        platformUsed: null,
        otherInformation: null,
        allInfo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加演习数据";
      let mizId = guid().replace(/-/g, '');
      this.form.id = mizId
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getActivedata(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改演习数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateActivedata(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addActivedata(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除演习数据编号为"' + ids + '"的数据项？').then(function() {
        return delActivedata(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/activedata/export', {
        ...this.queryParams
      }, `activedata_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
